<?php

namespace app\model;

use app\interface\ModelInterface;
use support\think\Model;

class BaseModel extends Model implements ModelInterface
{

  protected $connection = 'mysql';
  protected $pk = 'id';
  protected $convertNameToCamel = true;

  protected function init(): void
  {
    // 模型初始化
    $this->setOption('strict', false);
  }

  public function merge(array &$retArray, array $methodNames): array
  {
    foreach ($methodNames as $k => $v) {
      //如果$k为数字键，则直接调用方法$v
      $methodName = sprintf("get%sArray", ucfirst(is_int($k) ? $v : $k));
      // 非数字键，则调用getXXXArray方法,将$v作为参数
      if (method_exists($this, $methodName)) {
        $retArray = array_merge($retArray, $this->$methodName($v));
      }
    }
    return $retArray;
  }
}
